package com.meitutest.autoscript;

import android.support.test.uiautomator.UiDevice;

import com.meitutest.autoscript.utils.TestReport;

import java.util.Random;

/**
 * Created by CrystalChen on 2017/12/15.
 */

public class DeviceUtils {
    UiDevice uiDevice;
    Random random;

    public DeviceUtils(UiDevice uiDevice) {
        this.uiDevice = uiDevice;
        random = new Random();
    }

    public boolean isInPkg(String pkg) {
        String currentPkg = uiDevice.getCurrentPackageName();
        return currentPkg.equals(pkg);
    }

    /**
     * 随机点击屏幕
     */
    public void randomClick() {
        int x = random.nextInt(uiDevice.getDisplayWidth());
        int y = random.nextInt(uiDevice.getDisplayHeight());
        uiDevice.click(x, y);
        TestReport.i("DeviceUtils_randomClick: 随机点击（" + x + "," + y + "）");
    }


}
